package org.netty.udp.client.handler;

import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.DatagramPacket;

public class UdpNettyClientHandler extends SimpleChannelInboundHandler<DatagramPacket> {

	private Logger logger = LoggerFactory.getLogger(UdpNettyClientHandler.class);
	
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket packet) throws Exception {
        String msg = packet.content().toString(Charset.forName("UTF-8"));
        logger.info(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + " UDP client received: " + msg);
    }

}
